<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>03_变量的解构赋值</title>
</head>
<body>
<!--
1. 理解:
  * 从对象或数组中提取数据, 并赋值给变量(多个)
2. 对象的解构赋值
  let {n, a} = {n:'tom', a:12}
3. 数组的解构赋值
  let [a,b] = [1, 'atguigu'];
4. 用途
  * 给多个形参赋值
-->
<script type="text/javascript">
  let obj={username:'kebo',age:29}
  // let username=obj.username;
  // let username=obj.age;
  // 左边 定义的相当于全局变量
  let{username,age}=obj;
  console.log(username)
  console.log(age)

  let arr=[1,2,3,'abc',true];
  // let [a,b,c,d,e]=arr;
  let [,,a,b]=arr;
  console.log(a,b)
  // 应用 给形参复制
  /*function foo(obj) {
      console.log(obj.username,obj.age)
  }*/
  function foo({username,age}) {
      console.log(username,age)
  }
  foo(obj)
</script>
</body>
</html>